Useful Functions
random
​
Returns a random number inside a given interval
It can also give you a random element from a list:
RANDOM SEED
lerp
and lerpColor
​
This is basically what allows you to make gradients:
p5.Vector
​
A p5.Vector
is a type that holds two (or three) coordinates : x, y and z.
It has a lot of useful methods like getting its length or direction, and you can do math operations with them.
PS: check the documentation!
One nice thing in particular is that you can create them from an angle:
Transforms: translate
, rotate
and scale
​
When you start doing more complex things, keeping track of all the relative coordinates can get very annoying: transforms can help you handle that very nicely!
Also, some things like drawing a square rotated by 45° cannot be done except with transforms!
tip
Here is a nice tutorial about transforms.
It is using Processing and not p5, but the functions are exactly the same!
(except that pushMatrix()
is called push()
in p5, and popMatrix()
is called pop()
.